<?php
namespace app\common\model;

use app\common\cache\CacheData;
class AgentType extends Base
{

    public function cacheData(){
        $data = $this -> select();
        if($data){
            foreach($data as &$value):
                $value = $value->toArray();
            endforeach;
        }
        return $data;
    }

    /*
     * 代理类型缓存
     * @param  [type] $id [description]
     * @return [type]             [description]
     */
    public static function agentTypeData($id=null){
        $CACHE = CacheData::getInstance('AgentType');
        //$CACHE->updateCache();
        $cacheData = $CACHE -> readCache();
        $data = [];
        foreach($cacheData as $cache):
            $data[$cache['id']] = $cache;
        endforeach;
        if(!is_null($id)){
            if(isset($data[$id])):
                return $data[$id];
            else:
                return false;
            endif;
        }else{
            return $data;
        }
    }

}
